<template>
    <rx-dialog @ok="submitForm" @cancel="closeWindow" :canceltext="$ti18('rxForm.closeBtn','关闭')">
        <a-form style="padding: 10px;" layout="vertical" class="rx-a-form-vertical">
            <a-form-item :label="i18n('sign.personSign','加签人员')">
                <rx-text-list
                    v-model="signUsers"
                    :textfield="'fullName'"
                    :valfield="'userId'"
                    @click="selectUsers"
                    style="margin-top: 5px;"
                >
                    <UserOutlined/>
                </rx-text-list>

            </a-form-item>
            <a-form-item :label="i18n('sign.opinion','消息')">
                <a-textarea v-model:value="opinion" style="width: 100%"/>
            </a-form-item>
        </a-form>

    </rx-dialog>
</template>

<script>
import {Util, RxTextList, RxDialog} from '@lowcode/jpaas-base-lib';
import {ShareDialog} from '@lowcode/jpaas-share-component';
import BpmtaskApi from "@/common/api/bpm/bpmTask";

export default {
    name: "BpmTaskAddSign",
    props: {
        taskId: {//流程任务Id
            type: String,
            required: true
        },
        layerid: String,
        destroy: Function
    },
    comments: {
        RxTextList,
        RxDialog
    },
    data() {
        return {
            labelCol: {span: 4},
            wrapperCol: {span: 8},
            opinion: '',

            msgTypes: [],
            signUsers: [],
            signUsersObj: "",
            rxtext: [
                {value: 'aaa', text: 'A'},
                {value: 'bbb', text: 'b'}
            ]
        }
    },
    methods: {
        i18n(name, text, key) {
            return this.$ti18(name, text, "bpmTask", key);
        },
        selectUsers() {
            let self = this;
            ShareDialog.openUserDialog({
                curVm: this, data: {single: false, initUsers: self.signUsers}, widthHeight: ['1000px', '600px']
            }, function (data) {
                var ary = [];
                for (let i = 0; i < data.length; i++) {
                    ary.push({userId: data[i].userId, fullName: data[i].fullName});
                }
                self.signUsers = ary
            })
        },
        closeUser(userId) {
            for (let i = 0; i < this.signUsers.length; i++) {
                if (this.signUsers[i].userId == userId) {
                    this.signUsers.splice(i, 1);
                    return;
                }
            }
        },
        closeWindow() {
            Util.closeWindow(this, 'cancel');
        },
        submitForm(e) {
            if (this.signUsers.length == 0 || this.opinion == '') {
                e.loading = false;
                this.$message.error(this.i18n('sign.selectUserTips', '请选择用户与填写意见！'));
                return;
            }
            var userIds = [];
            this.signUsers.forEach(item => {
                userIds.push(item.userId);
            });

            BpmtaskApi.addSignUser({
                taskId: this.taskId,
                toUserIds: userIds.join(','),
                opinion: this.opinion
            }).then(resp => {
                Util.closeWindow(this, 'ok');
            });
        }
    }
}
</script>

<style scoped>

</style>
